package com.xiaoxi.exam.bean.request;

import com.xiaoxi.exam.bean.SignCheck;
import com.xiaoxi.exam.bean.response.WxBaseResponse;
import com.xiaoxi.exam.utils.SignUtils;
import java.util.Objects;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 微信支付返回信息类
 *
 * @author loki
 */
@EqualsAndHashCode(callSuper = true)
@Data
@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.NONE)
public class WxPayResultNotifyRequest extends WxBaseResponse implements SignCheck {

  //应用ID
  @XmlElement
  private String appid;
  //商户号
  @XmlElement
  private String mch_id;
  //设备号
  @XmlElement
  private String device_info;
  //随机字符串
  @XmlElement
  private String nonce_str;
  //签名
  @XmlElement
  private String sign;
  //用户标识
  @XmlElement
  private String openid;
  //是否关注公众账号
  @XmlElement
  private String is_subscribe;
  //交易类型
  @XmlElement
  private String trade_type;
  //付款银行
  @XmlElement
  private String bank_type;
  //总金额
  @XmlElement
  private int total_fee;
  //货币种类
  @XmlElement
  private String fee_type;
  //现金支付金额
  @XmlElement
  private Integer cash_fee;
  //现金支付货币类型
  @XmlElement
  private String cash_fee_type;
  //代金券金额
  @XmlElement
  private Integer coupon_fee;
  //代金券使用数量
  @XmlElement
  private Integer coupon_count;

  //代金券ID
  @XmlElement
  private String coupon_id_$n;

  //单个代金券支付金额
  @XmlElement
  private Integer coupon_fee_$n;

  //微信支付订单号
  @XmlElement
  private String transaction_id;
  //商户订单号
  @XmlElement
  private String out_trade_no;
  //商家数据包
  @XmlElement
  private String attach;
  //支付完成时间
  @XmlElement
  private String time_end;

  @Override
  public boolean signValid(String apiKey) {
    return Objects.nonNull(sign) && sign.equals(SignUtils.generateSign(this, apiKey));
  }
}
